// JavaScript Document
window.onload = function() {
	// Check for LocalStorage support.
	if (localStorage) {
		// Populate the form fields
		populateForm();

		// Get the form
		var form = document.getElementById("jsquiz");

		// Event listener for when the bookings form is submitted.
		form.addEventListener("submit", function(e) {
			saveData(form);
		});
	}
}

// Save the form data in LocalStorage.
function saveData() {

	var selectedAnswers = document.getElementById("message");
	var firstName = document.getElementById("firstName");
	var lastName = document.getElementById("lastName");
	
	// Retrieve the saved data and update the values of the form
	// fields.
	if (localStorage.getItem("firstName") != null){
		firstName.value = localStorage.getItem("firstName");
			}

	if (localStorage.getItem("lastName")!= null)  {
		 lastName.value = localStorage.getItem("lastName");
	}
	if (localStorage.getItem("selectedAnswers")!= null)  {
	selectedAnswers.innerHTML  = localStorage.getItem("selectedAnswers");
	}
}